﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:Controls="clr-namespace:BillsManager.Views.Controls">

    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="Values.xaml" />
    </ResourceDictionary.MergedDictionaries>

    <ControlTemplate x:Key="ErrorTemplate">

        <Border Background="{x:Null}"
                BorderBrush="{StaticResource ErrorTemplate.BorderBrush}"
                BorderThickness="1"
                CornerRadius="{StaticResource Control.Border.CornerRadius}">
            <Grid>
                <Path HorizontalAlignment="Right"
                      VerticalAlignment="Top"
                      Data="{StaticResource TopRightLittleCorner}"
                      Fill="{StaticResource ErrorTemplate.BorderBrush}" />
                <AdornedElementPlaceholder x:Name="adorner"
                                           Margin="-1"
                                           HorizontalAlignment="Stretch"
                                           VerticalAlignment="Stretch" />

                <Controls:PopupEx x:Name="errorPopup"
                                  AllowsTransparency="True"
                                  HorizontalOffset="2"
                                  Placement="Right"
                                  VerticalOffset="-1">
                    <Border Background="{StaticResource ErrorTemplate.BackgroundBrush}" CornerRadius="{StaticResource Control.Border.CornerRadius}">
                        <TextBlock Margin="4"
                                   Foreground="{StaticResource ErrorTemplate.ForegroundBrush}"
                                   Text="{Binding AdornedElement.(Validation.Errors).CurrentItem.ErrorContent,
                                                  ElementName=adorner}" />
                    </Border>
                </Controls:PopupEx>

            </Grid>
        </Border>

        <ControlTemplate.Triggers>

            <Trigger Property="IsMouseOver" Value="true">
                <Setter TargetName="errorPopup" Property="IsOpen" Value="True" />
            </Trigger>

            <Trigger Property="IsFocused" Value="true">
                <Setter TargetName="errorPopup" Property="IsOpen" Value="True" />
            </Trigger>

            <DataTrigger Binding="{Binding AdornedElement.IsMouseOver, ElementName=adorner}" Value="true">
                <Setter TargetName="errorPopup" Property="IsOpen" Value="True" />
            </DataTrigger>

            <DataTrigger Binding="{Binding AdornedElement.IsFocused, ElementName=adorner}" Value="true">
                <Setter TargetName="errorPopup" Property="IsOpen" Value="True" />
            </DataTrigger>

        </ControlTemplate.Triggers>

    </ControlTemplate>

</ResourceDictionary>